//
//  IntentViewController.m
//  QuickOrderCoffeeUI
//
//  Created by zxy on 2019/11/19.
//  Copyright © 2019 zxy. All rights reserved.
//

#import "IntentViewController.h"
#import "QuickOrderCoffeeIntentViewController.h"
#import "QuickOrderCoffeeIntent.h"
#import "QuickOrderCoffeeIntentViewController.h"
// As an example, this extension's Info.plist has been configured to handle interactions for INSendMessageIntent.
// You will want to replace this or add other intents as appropriate.
// The intents whose interactions you wish to handle must be declared in the extension's Info.plist.

// You can test this example integration by saying things to Siri like:
// "Send a message using <myApp>"

@interface IntentViewController ()

@end

@implementation IntentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

#pragma mark - INUIHostedViewControlling

// Prepare your view controller for the interaction to handle.
- (void)configureViewForParameters:(NSSet <INParameter *> *)parameters ofInteraction:(INInteraction *)interaction interactiveBehavior:(INUIInteractiveBehavior)interactiveBehavior context:(INUIHostedViewContext)context completion:(void (^)(BOOL success, NSSet <INParameter *> *configuredParameters, CGSize desiredSize))completion {
    // Do configuration here, including preparing views and calculating a desired size for presentation.
    
    if ([interaction.intent isKindOfClass:[QuickOrderCoffeeIntent class]]) {
        QuickOrderCoffeeIntentViewController *viewController = [[QuickOrderCoffeeIntentViewController alloc] initWithIntent:interaction.intent];
        [self attachChildViewController:viewController];
        completion(YES, parameters, CGSizeMake([self desiredSize].width, 100));
    }
    else {
        completion(false, parameters, [self desiredSize]);
    }
    
//    if (completion) {
//        completion(YES, parameters, [self desiredSize]);
//    }
}

- (CGSize)desiredSize {
    return [self extensionContext].hostedViewMinimumAllowedSize;
    //默认
    //return [self extensionContext].hostedViewMaximumAllowedSize;
}


- (void)attachChildViewController:(UIViewController *)viewController {
    [self addChildViewController:viewController];
    
    UIView *subView = viewController.view;
    [self.view addSubview:subView];
//    subVie
}
@end
